﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Handy_WPF.MVVM.Convert
{
    /// <summary>
    /// 性别转换【0-女 1-男】
    /// </summary>
    [ValueConversion(typeof(int), typeof(string))]
    public class SexConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int index = System.Convert.ToInt32(value);
            if (index == 0) return "女";
            return "男";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value?.ToString().Trim() == "女")
                return 0;
            return 1;
        }
    }
}
